#ifndef _NNSLITE_MTREE_H_
#define _NNSLITE_MTREE_H_

#include "nnsliteglobal.h"
#include "nnslitevector.h"
#include "nnslitedatapage.h"

/** nnsliteMTree */
struct nnsliteMTree;

struct nnsliteMTreeNode
{
	struct nnsliteMTree* pTree;
	u32 nodeIndex;
	u32 parentIndex;
	u32 childIndexes[NNSLITE_MTREE_MAX_CHILD];
	u32 childCount;
	u8  isLeaf;
	u32 depth;
	f64 radius;
	nnsliteObject object;
	nnsliteDataPage dataPage;
	u32 numObjectInPage;
};

struct nnsliteMTree
{
	nnsliteVector nodes;
	nnsliteDistFunc distfunc;
	u32 maxDepth;
	u32 maxPageObjectCount;
	u32 rootNodeIndex; /* the index of the root node in the nodes vector */
};

typedef struct nnsliteMTreeNode nnsliteMTreeNode;
typedef struct nnsliteMTree nnsliteMTree;

NNSLITE_RET nnsliteMTreeInit(nnsliteMTree* tree, nnsliteDistFunc func);
NNSLITE_RET nnsliteMTreeFree(nnsliteMTree* tree);
NNSLITE_RET nnsliteMTreeInsert(nnsliteMTree* tree, const nnsliteObject* object);
NNSLITE_RET nnsliteMTreeNNSearch(nnsliteMTree* tree, const nnsliteObject* object, u32 top, nnsliteObject* results);
NNSLITE_RET nnsliteMTreeWrite(nnsliteMTree* tree, FILE* fp);
NNSLITE_RET nnsliteMTreeRead(nnsliteMTree* tree, FILE* fp);
NNSLITE_RET nnsliteMTreePrint(nnsliteMTree* tree, FILE* fp);

#endif
